package _021_11_16

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func Print(pRoot *TreeNode) [][]int {
	ret := make([][]int, 0)
	node := make([]*TreeNode, 0)
	node = append(node, pRoot)
	for len(node) != 0 {
		size := len(node)
		ret = append(ret, []int{})
		for i := 0; i < size; i++ {
			if node[i].Left != nil {
				node = append(node, node[i].Left)
			}
			if node[i].Right != nil {
				node = append(node, node[i].Right)
			}

			ret[len(ret)-1] = append(ret[len(ret)-1], node[i].Val)
		}
		node = node[size:]
	}
	for i := 1; i < len(ret); i += 2 {
		temp := 0
		for j := 0; j < len(ret[i])/2; j++ {
			temp = ret[i][j]
			ret[i][j] = ret[i][len(ret[i])-1-i]
			ret[i][len(ret[i])-1-i] = temp
		}
	}
	return ret
}
